package test3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) {
        User user = new User();
        Scanner input = new Scanner(System.in);
        ObjectOutputStream oos = null;
        BufferedReader br = null;
        Socket socket = null;
        try {
            socket = new Socket("localhost",12345);
            System.out.print("请输入用户名:");
            user.setName(input.next());
            System.out.print("请输入用户密码:");
            user.setPasword(input.next());

            oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(user);
            oos.flush();
            br = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));
            String info = null;
            while ((info = br.readLine())!=null){
                System.out.println(info);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                oos.close();
                br.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
